<?php
$contact_id = (!empty($model->id))?$model->id:-1;

$form=$this->beginWidget('CActiveForm', array(
	'id'=>'contact-form',
	'enableAjaxValidation'=> true
)); ?>
    <div class="span2 bs-docs-sidebar">
        <ul class="nav nav-list bs-docs-sidenav affix" id="scrollspy">
            <li><a href="#contact_info"><i class="icon-chevron-right"></i> Thông tin liên hệ</a></li>
            <li><a href="#param_system"><i class="icon-chevron-right"></i> Tham biến hệ thống</a></li>
            <li><a href="#contact_circle"><i class="icon-chevron-right"></i> Tham gia nhóm liên hệ</a></li>
        </ul>
    </div>

    <div class="span10">
        <div class="well well-large">
            <form class="form-horizontal">
                <fieldset>
                    <legend id="contact_info">Thông tin liên hệ</legend>
                    <div class="control-group">
                        <?php echo $form->label($model,'email',array('class' => 'control-label')); ?>
                        <div class="controls">
                            <?php echo $form->textField($model,'email', array('placeholder' => 'Email','title' => 'Điền địa chỉ email liên hệ', 'class' => 'span8'));?>
                            <?php echo $form->error($model,'email',array('inputContainer' => 'span','errorCssClass' => 'errorMsg')) ?>
                        </div>
                    </div>
                    <legend id="param_system">Trường tham biến hệ thống</legend>
                    <div class="control-group">
                        <?php echo $form->label($model,'full_name',array('class' => 'control-label')); ?>
                        <div class="controls">
                            <?php echo $form->textField($model,'full_name', array('placeholder' => 'Họ tên','title' => 'Điền họ tên liên hệ', 'class' => 'span8'));?>
                            <?php echo $form->error($model,'full_name',array('inputContainer' => 'span','errorCssClass' => 'errorMsg')) ?>
                        </div>
                    </div>
                    <div class="control-group">
                        <?php echo $form->label($model,'phone',array('class' => 'control-label')); ?>
                        <div class="controls">
                            <?php echo $form->textField($model,'phone', array('placeholder' => 'Số điện thoại','title' => 'Điền số điện thoại', 'class' => 'span8'));?>
                            <?php echo $form->error($model,'phone',array('inputContainer' => 'span','errorCssClass' => 'errorMsg')) ?>
                        </div>
                    </div>
                    <div class="control-group">
                        <?php echo $form->label($model,'address',array('class' => 'control-label')); ?>
                        <div class="controls">
                            <?php echo $form->textField($model,'address', array('placeholder' => 'Địa chỉ liên hệ','title' => 'Điền địa chỉ liên hệ', 'class' => 'span8'));?>
                            <?php echo $form->error($model,'address',array('inputContainer' => 'span','errorCssClass' => 'errorMsg')) ?>
                        </div>
                    </div>

                    <legend id="contact_circle">Tham gia nhóm liên hệ</legend>
                    <div class="control-group">
                    <?php 
                        if($model->isNewRecord){
                            $this->widget('zii.widgets.grid.CGridView', array(
                                'id'=>'circle-grid',
                                'dataProvider'=> $circle->search(),
                                // 'filter'=>$circle,
                                'selectableRows' => 2,
                                'columns'=>array(
                                    array(
                                        'class' => 'CCheckBoxColumn',   
                                        'name' => 'id',
                                        'checked' => "",
                                        'checkBoxHtmlOptions' => array(
                                            'name' => 'Circles[]'
                                        )
                                    ),
                                    array(
                                        'name' => 'name',
                                    ),
                                    array(
                                        'name' => 'description',
                                    )
                                ),
                            ));
                        }else{
                            $this->widget('zii.widgets.grid.CGridView', array(
                                'id'=>'circle-grid',
                                'dataProvider'=> $circle->search(),
                                // 'filter'=>$circle,
                                'columns'=>array(
                                    array(
                                        'name' => 'name',
                                     ),
                                    array(
                                        'name' => 'description',
                                     ),
                                    array(
                                        'header' => 'Trạng thái',
                                        'type' => 'html',
                                        'value' => '$data->hasJoinedCircle('.$contact_id.', true)',
                                        'htmlOptions' => array(
                                            'style' => 'width:120px;text-align:center'
                                        )
                                    ),
                                    array(
                                        'header' => '',
                                        'type' => 'html',
                                        'value' => '$data->joinToCircleLink('.$contact_id.')'
                                    ),
                                ),
                            ));
                        }
                    ?>
                    </div>                    

                    <div class="form-actions">
                        <button type="submit" class="btn btn-primary">Lưu</button>
                        <button type="button" class="btn">Hủy</button>
                    </div>
                </fieldset>
            </form>
        </div>
    </div>

<?php $this->endWidget(); ?>
<script>
	$(function(){
		$('body').attr('data-spy','scroll');
		$('body').attr('data-target','#scrollspy');
	});
</script>